﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using TTGame;

public class DamageReceiverSectorCollider : DamageReceiverCollider {
    #region Fields

    public Transform directObj;

    public float radius;
    public float angle;

    #endregion Fields

    #region Methods
    public void Init(Transform bindTF, float aRadius, float aAngle, LayerMask layerMask) {

        radius = aRadius;
        angle = aAngle;
        directObj = bindTF;
        layersToHit = layerMask;
        if(bindTF != null) {
            directObj = bindTF;
        } else {
            directObj = transform;
        }
        init();
    }

    public override void CheckInsideColliderRay() {
        Collider[] s1 = Physics.OverlapSphere(directObj.position, radius, layersToHit.value);
        for(int i = 0; i < s1.Length; i++) {
            //碰撞检测OK了，那距离肯定是够了的！只要判断角度即可了。
            if(false == Tools.IsPointAngleInCircularSector(s1[i].transform.position, directObj.position, directObj.forward, angle)) {
                s1[i] = null;
            }
        }
        AddColliers(s1);
    }

    public override bool PointInsideCollider(Vector3 aPoint) {
        return false;
    }


    void OnDrawGizmos() {
        if(DamageReceiverCollider.IsDrawColliderWire == false) {
            return;
        }
        if(directObj == null) {
            return;
        }
        Tools.DrawSector(directObj.position, directObj.forward, radius, angle);
    }

    #endregion Methods
}